
import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/base/utils/mTopBar.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';

typedef void ClickCallback();
class ZJTopBar {
  Widget child; //child
  String title; //标题文本
  bool centerTitle = false; //是否居中显示title，默认否
  bool hideleftIcon = false; //是否隐藏左侧图标，默认不隐藏
  IconData leftButtonIcon; //左侧图标
  Color leftButtonColor= SQColor.black_333333; //左侧图标颜色
  ClickCallback onLeftButtonIconClick; //左侧图标点击的回调事件
  IconData rightButtonIcon; //右侧图标
  Color rightButtonColor= SQColor.theme_color; //右侧图标颜色
  ClickCallback onRightButtonIconClick; //右侧图标点击事件
  String rightButtonText; //右侧文本
  ClickCallback onRightButtonClick; //右侧文本点击事件
  Color backgroundColor=SQColor.white; //背景颜色
  Color titleTextColor=SQColor.black_333333;
  Color rightButtonTextColor=SQColor.theme_color;
  PreferredSizeWidget bottom;
  double elevation; //海拔
  List<Widget> actions;
  Widget leading;

  ZJTopBar({
    Key key,
    this.child,
    this.title,
    this.centerTitle = false,
    this.hideleftIcon = false,
    this.leftButtonIcon,
    this.leftButtonColor,
    this.onLeftButtonIconClick,
    this.rightButtonIcon,
    this.rightButtonColor,
    this.onRightButtonIconClick,
    this.rightButtonText,
    this.rightButtonTextColor,
    this.onRightButtonClick,
    this.backgroundColor,
    this.titleTextColor,
    this.bottom,
    this.elevation,
    this.actions,
    this.leading,
  });

  PreferredSizeWidget create() {
    return _appBar();
  }

  _appBar() {
    if (child != null) {
      return AppBar(
        title: child,
        actions: actions,
        automaticallyImplyLeading: false,
        backgroundColor: backgroundColor == null ? SQColor.white : backgroundColor,
        bottom: bottom,
        leading: leading,
        elevation: elevation,
        brightness: Brightness.light,
      );
    }
    return MTopBar(
      title: title,
      centerTitle:  centerTitle,
      hideleftIcon: hideleftIcon,
      leftButtonIcon: leftButtonIcon,
      leftButtonColor: leftButtonColor==null ? SQColor.black_333333:leftButtonColor,
      onLeftButtonIconClick: onLeftButtonIconClick,
      rightButtonIcon: rightButtonIcon,
      rightButtonColor: rightButtonColor==null ? Color(0xff165DFF):rightButtonColor,
      onRightButtonIconClick: onRightButtonIconClick,
      rightButtonText: rightButtonText,
      rightButtonTextColor: rightButtonTextColor==null ? SQColor.theme_color:rightButtonTextColor,
      onRightButtonClick: onRightButtonClick,
      backgroundColor: backgroundColor==null ? SQColor.white:backgroundColor,
      titleTextColor: titleTextColor==null ? SQColor.black_333333:titleTextColor,
      bottom: bottom,
      elevation: elevation,
      actions: actions,
      iconColor: SQColor.black_333333,
      brightness: Brightness.light
    ).create();
  }


  /**
   * 为白底topbar，设置Indicator颜色
   */
  static Color getTabIndicatorColor(){
    return Color(0xFF165DFF);
  }

  /**
   * 选中标签页的文本颜色
   */
  static Color getLabelColor(){
    return Color(0xFF165DFF);
  }

  /**
   * 未选中标签页的文本样式
   */
  static Color getUnselectedLabelColor(){
    return  Color(0xFF333333);
  }
}